package com.lwj.liwanjia.view.activity.personal.qian_bao;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.bean.QianbaoBean;
import com.lwj.liwanjia.impl.QiabaoView;
import com.lwj.liwanjia.presenter.QianbaoPresenter;
import com.lwj.liwanjia.utils.SpfUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by 001 on 2017/9/11.
 */

public class QianBaoActivity extends BaseActivity implements QiabaoView {


    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.tv_zong_money)
    TextView tvZongMoney;
    @BindView(R.id.tv_yikaotong_yue)
    TextView tvYikaotongYue;
    @BindView(R.id.tv_dongjie_yue)
    TextView tvDongjieYue;
    @BindView(R.id.tv_bangding_yue)
    TextView tvBangdingYue;

    private QianbaoPresenter presenter;
    private String allMoney;
    private String oneCardMoney;
    private String oneCardBoundMoney;

    @Override
    protected void initView() {
        tvLeft.setVisibility(View.VISIBLE);
        tvTitle.setText("我的钱包");
        ivRight.setVisibility(View.VISIBLE);
        ivRight.setImageResource(R.mipmap.saoyisao);
        presenter = new QianbaoPresenter(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_qian_bao;
    }


    @Override
    protected void onResume() {
        super.onResume();
        presenter.getQianbaoData(SpfUtils.getSpfUtils(this).getToken());
    }

    @OnClick({R.id.tv_left, R.id.iv_right, R.id.tv_shoukuan, R.id.tv_fukuan, R.id.tv_zhuanzhang, R.id.rl_chongzhi, R.id.rl_tixian, R.id.rl_mingxi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_left:
                finish();
                break;
            case R.id.iv_right://扫一扫
            case R.id.tv_shoukuan://收款
            case R.id.tv_fukuan://付款
                Toast.makeText(this, "暂未开通", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_zhuanzhang://转账
                startActivity(new Intent(this, ZhuanZhangActivity.class));
                break;
            case R.id.rl_chongzhi://充值
                Intent intent = new Intent(this, ChongZhiActivity.class);
                intent.putExtra("moneyCenter", allMoney);
                startActivity(intent);
                break;
            case R.id.rl_tixian://提现
                Intent yuIntent = new Intent(this, YuErTiKuanActivity.class);
                startActivity(yuIntent);
                break;
            case R.id.rl_mingxi://收支明细
                startActivity(new Intent(this, ShouZhiMingXiActivity.class));
                break;
        }
    }

    @Override
    public void showError(Exception e) {
        Toast.makeText(this, "访问网络失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void getQiaobaoData(QianbaoBean qianbaoBean) {
        if (qianbaoBean.getState() == 0) {
            Toast.makeText(this, "数据加载失败", Toast.LENGTH_SHORT).show();
        } else if (qianbaoBean.getState() == 1) {
            allMoney = qianbaoBean.getData().getAllMoney();
            oneCardMoney = qianbaoBean.getData().getOneCardMoney();
            oneCardBoundMoney = qianbaoBean.getData().getOneCardBoundMoney();
            tvZongMoney.setText(allMoney);
            tvYikaotongYue.setText(oneCardMoney);
            tvBangdingYue.setText(oneCardBoundMoney);
            tvDongjieYue.setText(qianbaoBean.getData().getFreeze());
        }
    }
}
